package git.determinal.template;

import git.determinal.template.mapper.TemplateMapper;
import git.determinal.template.model.Template;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * @Description
 * @Author determinal
 * @Date 2024/6/20 下午2:32
 */
@MapperScan("git.determinal.template.mapper")
public class SqlSessionContextTest {
    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        SqlSessionFactory sqlSessionFactory = applicationContext.getBean("sqlSessionFactory", SqlSessionFactory.class);
//        userService.show();
//        System.out.println(sqlSessionFactory);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        TemplateMapper mapper = sqlSession.getMapper(TemplateMapper.class);
        List<Template> result = mapper.getAll();
//        String result = sqlSession.selectOne("git.determinal.template.mapper.TemplateMapper.getOne");
        sqlSession.commit();
        sqlSession.close();
        System.out.println(result);

        //============================================
        /*// 静态工厂方法
        InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
        // 无参构造实例化
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        // 实例工厂方法
        SqlSessionFactory sqlSessionFactory = builder.build(in);*/
    }
}
